#include<iostream>
using namespace std;
const int N = 15;
int col[N], dg[N * 2], udg[N * 2];
int path[N];
int n;
int ans;
void dfs(int x)
{
	if (x == n + 1) {
		ans++;
		if (ans <= 3) {
			for (int i = 1; i <= n; i++) {
				cout << path[i] << " ";
			}
			cout << endl;
		}
		return;
	}
	for (int i = 1; i <= n; i++) {
		if (!col[i] && !dg[i + x] && !udg[i - x + n]) {
			col[i] = dg[i + x] = udg[i - x + n] = 1;
			path[x] = i;
			dfs(x + 1);
			path[x] = 0;
			col[i] = dg[i + x] = udg[i - x + n] = 0;
		}
	}
}
int main()
{
	cin >> n;
	dfs(1);
	cout << ans << endl;
	return 0;
}